﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace Web_cuiki
{
    public partial class WebForm7 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Membership.GetUser() == null)
            {
                this.Response.Redirect("Login.aspx");
            }
            if (Page.IsPostBack == false)
            {
                UserName.Text = Membership.GetUser().UserName;
                UserName.ReadOnly = true;
                Email.Text = Membership.GetUser().Email;
            }
        }

        protected void LoginButton_Click(object sender, EventArgs e)
        {
            if (OldPassword.Text != "")
            {
                Membership.GetUser().ChangePassword(OldPassword.Text, NewPassword.Text);
            }
            try
            {
                MembershipUser user = Membership.GetUser();
                user.Email = Email.Text;
                Membership.UpdateUser(user);
            }
            catch (System.Configuration.Provider.ProviderException ex)
            {
                  Msg.Text = ex.Message;
            } 
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

            if (OldPassword.Text != "")
            {
                Membership.GetUser().ChangePassword(OldPassword.Text, NewPassword.Text);
            }
            try
            {
                MembershipUser user = Membership.GetUser();
                user.Email = Email.Text;
                Membership.UpdateUser(user);
            }
            catch (System.Configuration.Provider.ProviderException ex)
            {
                Msg.Text = ex.Message;
            } 
        }
    }
}